<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2016/3/8
  Time: 13:42
  To change this template use File | Settings | File Templates.
--%>
<%@page import="com.eportal.util.WebUtil"%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>应用修改</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
    <meta name="renderer" content="webkit">
    <link href="${pageContext.request.contextPath}/static/css/common.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/bootstrap-3.3.5/css/bootstrap.min.css"
          rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/font-awesome-4.3.0/css/font-awesome.min.css"
          rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/select2-4.0.0/dist/css/select2.min.css"
          rel="stylesheet"/>
	<link href="${pageContext.request.contextPath}/static/plugins/layer/skin/layer.css" rel="stylesheet">

    <script src="${pageContext.request.contextPath}/static/js/jquery-1.11.3.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/bootstrap-3.3.5/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/select2-4.0.0/dist/js/select2.min.js"></script>
	<script src="${pageContext.request.contextPath}/static/plugins/layer/layer.js" type="text/javascript"></script>
	<script type="text/javascript"
            src="${pageContext.request.contextPath}/static/plugins/My97DatePicker/WdatePicker.js"></script>
			<style>
		.jqGrid_wrapper{*+margin-left:270px;}
	
		.lt,.col-sm-3,.col-sm-8{float:left}
		.form-group{*+overflow:hidden;}
		.form-group label{width:28%\9;*+width:20%;text-align:right\9;*+text-align:right;}
		.col-sm-8 .m-t2 {width:30%\9; *+width:36%;}
		.form-group .col-sm-8{width:66%\9;*+width:66%;}
		.form-group .form-control{*+width:95%;}
		.form-control{*+height:22px;}
		#sub{*+margin-right:10px;}
		.input-group .form-control{*+z-index:-1;}
		.upload{*+position:relative;}
		.btn-primary{*+position:absolute;*+left:431px;*+top:-35px;*+z-index:3;}
	</style>
</head>
<body>
<div class="col-sm-12">
    <form class="form-horizontal m-t"  id="uploadForm">
        <input type="hidden" name="sid" value="${appStore.sid}">
        <input type="hidden" name="agtCode" value="${appStore.sid}">
        <input type="hidden" name="WeChatSubIdHidden"  value="${appStore.gid}" />
        <a id="sure" onclick="sure()" hidden="true"></a>
        <div class="form-group">
            <label class="col-sm-3  control-label">应用ID:</label>
            <div class="col-sm-8">
                <input class="form-control"  size="30" value="${appStore.appid}" disabled="disabled"/>
            </div>
         </div>
        <div class="form-group">
            <label class="col-sm-3  control-label">所属公司:</label>
            <div class="col-sm-8">
                <input class="form-control" size="30" value="${appStore.agtname}" disabled="disabled"/>
            </div>
         </div>
         <div class="form-group">
            <label class="col-sm-3  control-label">关联小区:</label>
            <div class="col-sm-8">
                <input class="form-control"  size="30" value="${appStore.cname}" disabled="disabled" />
            </div>
         </div>
	    <div class="form-group">
               <label class="col-sm-3  control-label"><i class="require">*</i>应用状态:</label>
            <div class="col-sm-8">
                <select name="appType" class="form-control">
                    <option value="0">上架</option>
                    <option value="1">下架</option>
                </select>
            </div>
        </div>
       <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require">*</i>APP名称:</label>
            <div class="col-sm-8">
                <input class="form-control" name="appName" size="30"  value="${appStore.appName}"/>
            </div>
        </div>
       <div class="form-group">
            <label class="col-sm-3 col-sm-3 control-label">logo图片:</label>
            <div class="col-sm-8">
                <div class="input-group">
                    <input class="form-control" name="contentLogoImg" value="${appStore.logo_img}"  readonly size="30"/>
                    <div class="input-group-addon upload">
                        <input class="form-control" id="uploadLogoImg" type="file" name="upload1"
                               style="position: absolute;width: 60px;opacity: 0;"/>
                        <a class="btn btn-primary">上传</a>
                    </div>
                </div>
            </div>
        </div>
       <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require"></i>Android最新版本:</label>
            <div class="col-sm-8">
                <input class="form-control" name="androidVer" id="androidVer" size="30"  placeholder="格式类型如：1.2.1" value="${appStore.android_Ver}"/>
            </div>
        </div>
       <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require"></i>Android版本号code(低于此版本的app，会提示更新到新版本):</label>
            <div class="col-sm-8">
                <input class="form-control" name="androidVerCode" id="androidVerCode" size="30" placeholder="对应于Android version code" value="${appStore.android_Ver_Code}"/>
            </div>
       </div>
       
       <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require"></i>Android的强制更新版本号:</label>
            <div class="col-sm-8">
                <input class="form-control" name="androidVerLimit" id="androidVerLimit" placeholder="强制更新的版本号，低于此版本会被强制更新" size="30" value="${appStore.android_Ver_Limit}"/>
            </div>
        </div>
       <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require"></i>Android更新提示:</label>
            <div class="col-sm-8">
                <input class="form-control" name="androidVerTip" id="androidVerTip" size="30" placeholder="Android提示更新时的说明"  value="${appStore.android_Ver_Tip}"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 col-sm-3 control-label">上传Android资源:</label>
            <div class="col-sm-8">
                <div class="input-group">
                    <input class="form-control" name="content" value="${appStore.android_download_app}"  readonly size="30"/>
                    <div class="input-group-addon upload">
                        <input class="form-control" id="upload" type="file" name="upload"
                               style="position: absolute;width: 60px;opacity: 0;"/>
                        <a class="btn btn-primary">上传</a>
                    </div>
                </div>
            </div>
        </div>
       <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require"></i>iOS的最新版本号(低于此版本的app，会提示更新到新版本):</label>
            <div class="col-sm-8">
                <input class="form-control" name="iosVer" id="iosVer" size="30" placeholder="格式类型如：1.2.1" value="${appStore.ios_Ver}"/>
            </div>
        </div>
         <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require"></i>iOS强制更新的版本号:</label>
            <div class="col-sm-8">
                <input class="form-control" name="iosVerLimit" id="iosVerLimit" placeholder="格式类型如：1.2.1" size="30" value="${appStore.ios_Ver_Limit}"/>
            </div>
        </div>
       <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require"></i>iOS更新提示:</label>
            <div class="col-sm-8">
                <input class="form-control" name="iosVerTip" id="iosVerTip" size="30" placeholder="iOS提示更新时的说明" value="${appStore.ios_Ver_Tip}"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require"></i>iOS地址:</label>
            <div class="col-sm-8">
                <input class="form-control" name="iosUpdateUrl" id="iosUpdateUrl" placeholder=""  size="100" value="${appStore.ios_Update_Url}"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require"></i>腾讯微下载地址:</label>
            <div class="col-sm-8">
                <input class="form-control" name="wxzUrl" id="wxzUrl" placeholder=""  size="100" value="${appStore.wxz_Url}"/>
            </div>
        </div>
         <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require">*</i>推送服务的app_id:</label>
            <div class="col-sm-8">
                <input class="form-control" name="pushAppId" size="30" value="${appStore.PUSH_APP_ID}"/>
            </div>
        </div>
         <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require">*</i>推送服务的app_secret:</label>
            <div class="col-sm-8">
                <input class="form-control" name="pushAppSecret" size="30" value="${appStore.PUSH_APP_SECRET}"/>
            </div>
        </div>
         <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require">*</i>推送服务的app_key:</label>
            <div class="col-sm-8">
                <input class="form-control" name="pushAppKey" size="30" value="${appStore.PUSH_APP_KEY}"/>
            </div>
        </div>
         <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require">*</i>推送服务的master_secret:</label>
            <div class="col-sm-8">
                <input class="form-control" name="pushMasterSecret" size="30" value="${appStore.PUSH_MASTER_SECRET}"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require">*</i>微信公众号名称:</label>
            <div class="col-sm-8">
                <input class="form-control" name="WeChatSubscription" id="WeChatSubscription"  size="30" value="${appStore.cname1}"/>
            </div>
         </div>
         <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require">*</i>微信公众号原始id:</label>
            <div class="col-sm-8">
             <%-- <c:if test="${empty appStore.gid}"> --%>
             	<input class="form-control" name="WeChatSubIdWeb"  id="WeChatSubIdWeb" size="30" value="${appStore.gid}" />
          <%--    </c:if>
             <c:if test="${not empty appStore.gid}">
             	<input class="form-control" size="30" value="${appStore.gid}" disabled="disabled"/>
             </c:if> --%>
                
            </div>
         </div>
         <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require">*</i>微信产品的product_id:</label>
            <div class="col-sm-8">
                <input class="form-control" name="WeChatProductId" id="WeChatProductId" size="30" value="${appStore.product_id}"/>
            </div>
         </div>
         <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require">*</i>微信公众号的app_id:</label>
            <div class="col-sm-8">
                <input class="form-control" name="wxAppId" size="30" value="${appStore.WX_APP_ID}"/>
            </div>
        </div>
         <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require">*</i>微信公众号的app_secret:</label>
            <div class="col-sm-8">
                <input class="form-control" name="wxAppSecret" size="30" value="${appStore.WX_APP_SECRET}"/>
            </div>
        </div>
        
        <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require">*</i>微信公众号的EncodingAESKey:</label>
            <div class="col-sm-8">
                <input class="form-control" name="WeChatEncodingAESKey" id="WeChatEncodingAESKey" size="30" value="${appStore.encodingaeskey}"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require">*</i>微信公众号服务器配置token:</label>
            <div class="col-sm-8">
                <input class="form-control" name="WeChatToken"  id="WeChatToken" size="30" value="${appStore.grouptoken}"/>
            </div>
        </div>
        <div class="form-group">
               <label class="col-sm-3  control-label"><i class="require"></i>小程序:</label>
            <div class="col-sm-8">
                <select name="wxXcxId" class="form-control" id='wxXcxId'>
                	<c:forEach var="item" items="${xcxlist}" varStatus="status">
                	<option value="${item.sid}" >${item.cName }</option>
                	</c:forEach>
                </select>
            </div>
        </div>        
        <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require"></i>下载地址:</label>
            <div class="col-sm-8">
                <%=WebUtil.getReqPreUrl(request) %>u/b?i=${appStore.sid}
            </div>
        </div>
    </form>
</div>
<script type="text/javascript">
 
	$("select").val('${appStore.appType}');	
	$(function () {
		$("#upload").change(function () {
	        var filename = $(this).val();
	        var index = filename.lastIndexOf("\\");
	        $("input[name='content']").val(filename.substring(index + 1));
	    });
		
		$("#uploadLogoImg").change(function () {
	        var filename = $(this).val();
	        var index = filename.lastIndexOf("\\");
	        $("input[name='contentLogoImg']").val(filename.substring(index + 1));
	    });
		
	    $("#wxXcxId").val('${appStore.wx_xcx_id}');//设置默认选中只
	})
	function sure(){
    	var androidVer = $("#androidVer").val();
    	var androidVerLimit = $("#androidVerLimit").val();
    	var androidVerTip = $("#androidVerTip").val();
    	var androidVerCode = $("#androidVerCode").val();
    	var iosVer = $("#iosVer").val();
    	var iosVerLimit = $("#iosVerLimit").val();
    	var iosVerTip = $("#iosVerTip").val();
    	var WeChatSubscription = $("#WeChatSubscription").val();
		var WeChatSubIdWeb = $("#WeChatSubIdWeb").val();
		var WeChatProductId = $("#WeChatProductId").val();
		var WeChatEncodingAESKey = $("#WeChatEncodingAESKey").val();
		var iosUpdateUrl = $("#iosUpdateUrl").val();
		var WeChatToken = $("#WeChatToken").val();
    	var formData = new FormData($( "#uploadForm" )[0]); 
    	if(((androidVer=='' || androidVerTip=='' || androidVerCode=='' ))&&(androidVer!='' || androidVerTip!='' || androidVerCode!='')){
			alert("Android版本填写时，必须同时填写Android版本号，Android强制更新的版本号，Android更新提示和Android版本号code");
			return;
		}
    	if(((iosVer=='' || iosVerTip=='' ||iosUpdateUrl==''))&&(iosVer!='' || iosVerTip!='')){
			alert("iOS版本填写时，必须同时填写iOS版本号,和iOS更新提示");
			return;
		}
// 		if(androidVer=='' && iosVer==''){
// 			alert("Android版本或iOS版本号，必须选填其中一个");
// 			return;
// 		}
		var reg =new RegExp("^\\d{1,9}\.\\d{1,9}\.\\d{1,9}$");
		if(androidVer!='' && !(reg.test(androidVer))){
           	alert("Android版本号格式错误，必须含有2个小数点，小数前后都为数字");
	    	$("#sub").removeAttr("disabled");
	    	return;
        }
		if(androidVerLimit!='' && !(reg.test(androidVerLimit))){
           	alert("Android强制更新的版本号错误，必须含有2个小数点，小数前后都为数字");
	    	$("#sub").removeAttr("disabled");
	    	return;
        }
		if(iosVer!='' && !(reg.test(iosVer))){
           	alert("iOS版本号格式错误，必须含有2个小数点，小数前后都为数字");
	    	$("#sub").removeAttr("disabled");
	    	return;
        }
		if(iosVerLimit!='' && !(reg.test(iosVerLimit))){
           	alert("iOS强制更新的版本号错误，必须含有2个小数点，小数前后都为数字");
	    	$("#sub").removeAttr("disabled");
	    	return;
        }
		if(!WeChatSubscription){
			alert("微信公众号名称不能为空");
			return;
		}
		if('${appStore.gid}'=='' && !WeChatSubIdWeb){
			alert("微信公众号原始id不能为空");
			return;
		}
		if(!WeChatProductId){
			alert("微信产品的product_id不能为空");
			return;
		}
		if(!WeChatEncodingAESKey){
			alert("微信公众号的EncodingAESKey不能为空");
			return;
		}
		if(!WeChatToken){
			alert("微信公众号服务器配置token不能为空");
			return;
		}
    	$.ajax({  
         url: '${pageContext.request.contextPath}/admin/appstore_update.action' ,  
         type: 'POST',  
         data: formData,  
         async: false,  
         cache: false,  
         contentType: false,  
         processData: false,  
         success: function (result) {  
              result = JSON.parse(result)
              if (result.code == 1) {
            		 var index = parent.layer.getFrameIndex(window.name);
                  parent.layer.close(index); 
              }else{
              	alert(result.msg);
              }
         },  
         error: function (returndata) {  
             alert(returndata);  
         }  
    	});
    }
</script>
</body>
</html>
